package models;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.Log;
import android.view.MotionEvent;

/**
 * 
 * @author Merete, Mirna, Esben, Knut og Stian
 * 
 */
public class Pig extends PhysicalObject {

	private static final String TAG = Pig.class.getSimpleName();
	private boolean isTouched;
	private Score score;
	
	public Pig(Bitmap bitmap, double x, double y, int width, int height) {
		super(bitmap, x, y, width, height);
		//Initial score is 0.
		score = new Score();
		active = true;
		// TODO Auto-generated constructor stub
	}

	public void update() {
		// if breaking is complete, move to constant speed
		/*if(motion.getAccX() >= 0 || motion.getXv() > 2){
			motion.setXv(2);
			motion.setAccX(0);
		}*/
		
		
		// accelerate
		motion.setXv(motion.getXv() + motion.getAccX());
		motion.setYv(motion.getYv() + motion.getAccY());
		
		//Log.d(TAG, "Acceleration: " + motion.getAccX());
		//Log.d(TAG, "Speed: " + motion.getXv());
		
		// update position
		x = motion.getXv() + x;
		y = motion.getYv() + y;
		
		// stops the pig from exiting the screen;
		if(x < 0){
			x = 0;
		} else if(x > 270){
			x = 270;	
		}

		// move rectangle
		rect.set((int) x, (int) y, spriteWidth + (int) x, spriteHeight
				+ (int) y);
		
		

	}

	public void draw(Canvas canvas) {
		canvas.drawBitmap(bitmap, (float) getX(), (float) getY(), null);
	}

	public void handleMotionEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
				motion.setAccX(0);
				motion.setXv(0.8);
		} else if (event.getAction() == MotionEvent.ACTION_UP) {
			motion.setAccX(-0.02);
		}
	}

}
